{{ define "main" }}

{{ .Scratch.Set "skipSeeAlso" true }}

{{ partial "primary_top.html" . }}

{{ if not .Params.skip_list }}
    <p>{{ .Description }}</p>
{{ end }}

{{ if .Params.list_below }}
    {{ .Content }}
{{ end }}

{{ if not .Params.skip_list }}
    <div class="section-index">
        {{ $pages := (where .Site.Pages "Section" .Section) }}

        {{ if .Params.list_by_publishdate }}
            {{ $pages = sort $pages ".Params.publishdate" "desc" }}
        {{ end }}

        {{ $parent := .Page }}
        {{ $parentDir := (path.Dir .Page.File.Dir) }}

        {{ if $parent.Params.simple_list }}
            <ul>
                {{ range $pages }}
                    {{ $pageLocation := (path.Dir (path.Dir .File.Dir)) }}
                    {{ if eq $parentDir $pageLocation }}
                        <li><a href="{{ .Permalink }}">{{- .Title -}}</a></li>
                    {{ end }}
                {{ end }}
            </ul>
        {{ else }}
            {{ range $pages }}
                {{ $pageLocation := (path.Dir (path.Dir .File.Dir)) }}
                {{ if eq $parentDir $pageLocation }}
                    <div class="entry">
                        <h5>
                            <a href="{{ .Permalink }}">
                                {{- if .Params.icon -}}<i class="page-icon">{{- partial "icon.html" .Params.icon -}}</i>{{- end -}}{{- .Title -}}
                            </a>
                        </h5>
                        <p>{{ .Description }}</p>
                    </div>
                {{ end }}
            {{ end }}
        {{ end }}
    </div>
{{ end }}

{{ if not .Params.list_below }}
    {{ .Content }}
{{ end }}

{{ partial "primary_bottom.html" . }}

{{ end }}